import { makeAutoObservable } from 'mobx';
import { inject, injectable } from 'inversify';
import { UserModel } from '../models/user.model.ts';
import { LogoutUseCase } from '../usecase/logoutUseCase.ts';

@injectable()
export class UserViewModel {
  get user() {
    return this.userModel.user;
  }

  get loading() {
    return this.userModel.loading;
  }

  get userInitials(): string {
    return (
      this.user.firstName.substring(0, 1).toUpperCase() +
      this.user.lastName.substring(0, 1).toUpperCase()
    );
  }

  constructor(
    @inject(UserModel)
    private userModel: UserModel,
    @inject(LogoutUseCase)
    private logoutUseCase: LogoutUseCase,
  ) {
    makeAutoObservable(this);
  }

  userLogout() {
    this.logoutUseCase.execute();
  }
  dispose() {
    this.userModel.dispose();
  }
}
